/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   edw_types.h
 * Author: edw200
 *
 * Created on 2018年3月29日, 上午10:53
 */

#ifndef XAG_TYPES_H
#define XAG_TYPES_H

#ifdef __cplusplus
extern "C"
{
#endif

#include <stdio.h>
#include <stdbool.h>

typedef unsigned char           XAG_U8;
typedef unsigned short          XAG_U16;
typedef unsigned int            XAG_U32;

typedef signed char             XAG_S8;
typedef short                   XAG_S16;
typedef int                     XAG_S32;

typedef float                   XAG_F32;
typedef double                  XAG_F64;

#ifdef _WIN32
    typedef __int64             XAG_U64;
    typedef __int64             XAG_S64;
#else
    typedef unsigned long long  XAG_U64;
    typedef long long           XAG_S64;
#endif

#ifdef __x86_64__
    typedef unsigned int        XAG_U32L;
    typedef int                 XAG_S32L;
#else
    typedef unsigned long       XAG_U32L;
    typedef long                XAG_S32L;
#endif
    
typedef char                    XAG_CHAR;
#define XAG_VOID                void
#define XAG_BOOL                bool
#define XAG_STRING              string 

#define XAG_SAFE_ALLOCA_STRING(...) \
({ \
    XAG_CHAR* __csString; \
    XAG_S32 __s32Len; \
    __s32Len = snprintf(NULL, 0, ##__VA_ARGS__); \
    __csString = (XAG_CHAR*)alloca(__s32Len); \
    sprintf(__csString, ##__VA_ARGS__); \
    __csString; \
})

typedef enum
{
    XAG_SUCCESS = 0 ,           // 成功
    XAG_FAILED,                 // 失败
    XAG_INIT,                   // 初始化状态
    XAG_TIMEOUT,                // 超时
    XAG_ILLEGALITY,             // 非法
    XAG_ERRORDATA,              // 数据错误
    XAG_KEEPWAIT,               // 等待中
    XAG_REPLY_FAILED,           // 应答失败
    XAG_FULL,                   // 缓冲满

    XAG_SYS_ERR,                // 系统接口错误
    XAG_SOCKET_ERR,             // socket创建错误
    XAG_LISTEN_ERR,             // 监听错误
    XAG_BIND_ERR,               // 绑定错误
    XAG_CONNECT_ERR,            // 连接错误
}XAG_CODE;

#ifdef __cplusplus
}
#endif

#endif /* XAG_TYPES_H */

